﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Guline.Web.XjsGame.Models;
namespace Guline.Web.XjsGame.Controllers
{
    public class BaseController : Controller
    {
        protected dnwebEntities db;
        protected List<Models.ICat> iCats;
        public BaseController()
        {
            //GRANT ALL PRIVILEGES ON *.* TO 'dnsuper'@'124.158.10.238' IDENTIFIED BY '2381314521';
            db = new dnwebEntities();
            iCats = new List<ICat>();
            iCats.Add(new Models.ICat() { ID =0, Name = "Đại náo thiên cung" });
            iCats.Add(new Models.ICat() { ID = 92, Name = "Tin tức" });
            iCats.Add(new Models.ICat() { ID = 93, Name = "Sự kiện" });
            iCats.Add(new Models.ICat() { ID = 95, Name = "Hướng dẫn" });
            iCats.Add(new Models.ICat() { ID = 96, Name = "Bí kíp" });

            ViewBag.appConfig = db.configs.FirstOrDefault();

            ViewBag.iCats = iCats;
        }
        protected string GetIPAddress()
        {
            System.Web.HttpContext context = System.Web.HttpContext.Current;
            string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (!string.IsNullOrEmpty(ipAddress))
            {
                string[] addresses = ipAddress.Split(',');
                if (addresses.Length != 0)
                {
                    return addresses[0];
                }
            }

            return context.Request.ServerVariables["REMOTE_ADDR"];
        }
        public Int32 UnixTimeStampUTC()
        {
            Int32 unixTimeStamp;
            DateTime currentTime = DateTime.Now;
            DateTime zuluTime = currentTime.ToUniversalTime();
            DateTime unixEpoch = new DateTime(1970, 1, 1);
            unixTimeStamp = (Int32)(zuluTime.Subtract(unixEpoch)).TotalSeconds;
            return unixTimeStamp;
        }
    }
}
